import i18n from '@/lang';

// SIM 卡图标对象集
export const simCardIconObj = {
    service: require('@/assets/images/img_successfully@2x.png'),
    no_service: require('@/assets/images/img_warning_orange@3.png'),
    disconnected: require('@/assets/images/disconnected.png'),
    modem_init: require('@/assets/images/img_warning_orange@3.png'),
    sim_init: require('@/assets/images/img_warning_orange@3.png'),
    no_sim: require('@/assets/images/img_insert_sim_card@3.png'),
    pin_locked: require('@/assets/images/img_unlock_sim_card@3.png'),
    puk_locked: require('@/assets/images/img_unlock_sim_card@3.png'),
    sim_locked: require('@/assets/images/img_warning_orange@3.png'),
    IPPT: require('@/assets/images/img_successfully@2x.png'),
    ready: require('@/assets/images/img_successfully@2x.png'),
    error: require('@/assets/images/img_insert_sim_card@3.png')
};

// SIM 卡文字对象集
export const simCardTextObj = {
    service: i18n.t('dataBoard.successConnectTitle'),
    no_service: i18n.t('dataBoard.noServerTitle'),
    disconnected: i18n.t('dataBoard.disconnectedTitle'),
    modem_init: i18n.t('dataBoard.modemInitTitle'),
    sim_init: i18n.t('dataBoard.simInitTitle'),
    no_sim: i18n.t('dataBoard.insertSIMCardTitle'),
    pin_locked: i18n.t('dataBoard.lockSIMCardTitle'),
    puk_locked: i18n.t('dataBoard.lockSIMCardTitle'),
    sim_locked: i18n.t('dataBoard.SIMLockedTitle'),
    IPPT: i18n.t('common.enableLable'),
    ready: i18n.t('dataBoard.simConnectTitle'),
    error: i18n.t('dataBoard.simErrorTitle')
};

// 信号图标对象集
export const signalIconObj = {
    0: require('@/assets/images/Dashboard_img_signal_0@3.png'),
    1: require('@/assets/images/Dashboard_img_signal_1@3.png'),
    2: require('@/assets/images/Dashboard_img_signal_2@3.png'),
    3: require('@/assets/images/Dashboard_img_signal_3@3.png'),
    4: require('@/assets/images/Dashboard_img_signal_4@3.png')
};

// 是否运营商图标对象集
export const isISPobj = {
    off: require('@/assets/images/radio-off@3.png'),
    on: require('@/assets/images/radio-on@3.png')
};

// WiFi 图标对象集
export const wifiIcon = {
    off: require('@/assets/images/wifi off@2x.png'),
    on: require('@/assets/images/wifi on@2x.png')
};

// 密码图标对象集
export const passwordIcon = {
    hide: require('@/assets/images/eye_hide_new@3.png'),
    open: require('@/assets/images/eye_reveal_new@3.png')
};

// SIM 卡网络类型
export const mobileSignalTypes = ['3G', '4G', '5G', '4G5G', '4G+', '5G+'];

/**
 * 格式化流量，处理单个数据
 * @param {Number} data 流量数据
 */
export const formatTraffic = (data) => {
    // 非法数字时
    if (typeof data != 'number' || isNaN(data)) return `0 KB`;

    let number = 0;
    let unit = 'KB';

    // KB
    if (data < 1024 * 1024) {
        number = data / 1024;
    }

    // MB
    else if (data < 1024 * 1024 * 1024) {
        number = data / 1024 / 1024;
        unit = 'MB';
    }

    // GB
    else {
        number = data / 1024 / 1024 / 1024;
        unit = 'GB';
    }

    return `${number.toFixed(2)} ${unit}`;
};

/**
 * 格式化流量，求两个流量之和
 * @param {Number} data1
 * @param {Number} data2
 */
export const formatTrafficTotal = (data1, data2) => {
    // 非法数字时
    if (typeof data1 != 'number' || isNaN(data1) || typeof data2 != 'number' || isNaN(data2)) return `0 KB`;

    let number1 = 0;
    let number2 = 0;
    let unit = 'KB';

    // KB
    if (data1 + data2 < 1024 * 1024) {
        number1 = (data1 / 1024).toFixed(2);
        number2 = (data2 / 1024).toFixed(2);
    }

    // MB
    else if (data1 + data2 < 1024 * 1024 * 1024) {
        number1 = (data1 / 1024 / 1024).toFixed(2);
        number2 = (data2 / 1024 / 1024).toFixed(2);
        unit = 'MB';
    }

    // GB
    else {
        number1 = (data1 / 1024 / 1024 / 1024).toFixed(2);
        number2 = (data2 / 1024 / 1024 / 1024).toFixed(2);
        unit = 'GB';
    }

    return `${(Number(number1) + Number(number2)).toFixed(2)} ${unit}`;
};
